package gdconf

import (
	"server_cluster/common/logger"
)

// 道具分解配置表

type ItemResolveConfig struct {
	ItemId   int32    `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 道具id
	ItemList ItemList `csv:"Item_list,omitempty"`                       // 获得物品
}

func (i *ItemResolveConfig) TableName() string {
	return "config_item_resolve"
}

func (g *GameDataConfig) saveItemResolveConfig() {
	saveTableToDb[ItemResolveConfig](g.Db, readTable[ItemResolveConfig](g.CsvPathPrefix+"ItemResolve.csv"))
}

func (g *GameDataConfig) loadItemResolveConfig() {
	g.GameDataMaps.ItemResolveConfigMap = make(map[int32]*ItemResolveConfig)
	for _, itemResolveConfig := range loadTableFromDb[ItemResolveConfig](g.Db) {
		g.GameDataMaps.ItemResolveConfigMap[itemResolveConfig.ItemId] = itemResolveConfig
	}
	logger.Info("ItemResolveConfig Count: %v", len(g.GameDataMaps.ItemResolveConfigMap))
}

func GetItemResolveConfig(itemId int32) *ItemResolveConfig {
	value, exist := CONF.GameDataMaps.ItemResolveConfigMap[itemId]
	if !exist {
		logger.Error("[ConfigNotFound] ItemResolveConfig, itemId: %v", itemId)
		return nil
	}
	return value
}

func GetItemResolveConfigMap() map[int32]*ItemResolveConfig {
	return CONF.GameDataMaps.ItemResolveConfigMap
}
